package com.tianzeculture.stagebao.activity.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/6/6 0006.
 * 工作标签
 */

public class WorkTagAdapter extends BaseAdapter {
    Context context;
    List<String> strings;
    List<String> checkedTag;

    public WorkTagAdapter(Context context, List<String> strings) {
        this.context = context;
        this.strings = strings;
    }

    public void setCheckedTag(List<String> checkedTag) {
        this.checkedTag = checkedTag;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return strings.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_work_tag, null);
            holder.worktag = view.findViewById(R.id.boxWorkTag);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        setData(holder, i);
        return view;
    }

    private void setData(ViewHolder holder, int i) {
        holder.worktag.setText(strings.get(i));
        if (checkedTag == null) {
            holder.worktag.setChecked(false);
        } else {
            for (int k = 0; k < checkedTag.size(); k++) {
                if (strings.get(i).equals(checkedTag.get(k))) {
                    holder.worktag.setChecked(true);
                    break;
                }
            }
        }

    }


    class ViewHolder {
        CheckBox worktag;
    }
}
